package com.homelock.common.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class BasicController {

	protected static final String errormsg="操作失败,请联系系统管理员!";
	
	public <T> void sendJsonData(HttpServletResponse response,Object object){
		String json= JSON.toJSONString(object);
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out=null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.println(json);
			out.flush();
			out.close();
		}
		
	}
	
	protected String getErrorMsg(Exception e){
		if( null != e && e instanceof IllegalArgumentException){
			return e.getMessage();
		}
		return "操作失败";
	}
}
